<{include file="admin/header.html"}>
<div class="container">
	<div class="floattop">
		<div class="itemtitle">
			<h3>生产设备管理</h3>
			<ul class="tab1">
				<li><a href="facility_manage.php"><span>设备列表</span></a></li>
				<li><a href="?act=show_add_form"><span>添加设备</span></a></li>
			</ul>
		</div>
	</div>
	<div class="floattopempty"></div>

	<{if $show_add_form}>		
		<form id="formadd" action="?act=add" method="post" enctype="multipart/form-data">
			<table class="tb tb2">
				<tbody>

					<tr>
						<td class="td27" colspan="2">设备图片：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="file" type="file" value="" name="facility_images">
						</td>
						<td class="vtop tips2"></td>
					</tr>
									
					<tr>
						<td colspan="15">
							<input class="btn" type="submit" value="提交">
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	<{elseif $show_edit_form}>
		<form id="formedit" action="?act=save" method="post" enctype="multipart/form-data">
			<table class="tb tb2">
				<tbody>


					<tr>
						<td class="td27" colspan="2">设备图片：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="file" type="file" value="" name="facility_images"><br />
							<{if $facility.facility_images neq ''}><div class="facility-img"><img src="../upload/facility/<{$facility.facility_images}>" /><a href="#" class="del-img"> 删除图片</a></div><{/if}>
						</td>
						<td class="vtop tips2"></td>
					</tr>
							
					<tr>
						<td colspan="15">
							<input class="btn" type="submit" value="提交">
						</td>
					</tr>
				</tbody>
			</table>
		<input type="hidden" name="facility_id" value="<{$facility.facility_id}>">	
		<input type="hidden" name="o_facility_name" id="o_facility_name" value="<{$facility.facility_name}>">
		<input type="hidden" name="o_facility_images"  value="<{$facility.facility_images}>">		
		</form>		
		
	<{else}>
		<div class="list-div">
		<table class="tb tb2" cellspacing="1" cellpadding="3">
			<tbody>
				<tr class="header">
					<th>设备编号</th>
					<th>设备图片</th>
					<th>操作</th>
				</tr>
				<{foreach from=$facility_list item=fl}>
				<tr class="td-cls">
					<td><{$fl.facility_id}></td>
					<td><img src="../upload/facility/<{$fl.facility_images}>" width="120px" height="100px;" /></td>
					<td><span class="operation"><a href="?act=edit&facility_id=<{$fl.facility_id}>">编辑</a></span><span class="operation"><a href="#" rel="<{$fl.facility_id}>" class="del">删除</a></span></td>
				</tr>
				<{/foreach}>
				<tr><td colspan="8" class="pagenavigator"><{$pagenavigator}></td></tr>
			</tbody>
		</table>	
	</div>
	<{/if}>
<script type="text/javascript" src="../editor/xheditor.js"></script>	
<script type="text/javascript">
$(document).ready(function(){
	$('#formadd, #formedit').validate({
		rules: {
			facility_images: {required: true,accept:'gif|jpg|png'},
		},
		messages: {
			facility_images:{required:'请上传设备图片',accept:'图片格式不正确，请选择gif|jpg|png格式图片'}
		},
		success:function(label) { 
			label.html(" ").addClass("right");
		}
		
	});
});

$(".del").click(function(){
	if(confirm('删除后不能恢复，确认删除？')) {
		var obj = $(this);
		var facility_id = obj.parents('tr').find('td').eq(0).text();
		$.get('facility_manage.php', {act:'del', facility_id:facility_id}, function(data){ 
			if(data == 1) {
				alert('删除成功');
				obj.parents('tr').remove();	
			}
		});
	}
});

$(".del-img").click(function() { 
	if(confirm('删除后不能恢复，确认删除？')) {
		var obj = $(this);
		var facility_id = $("input[name='facility_id']").val();
		$.get('facility_manage.php', {act:'del_img', facility_id:facility_id}, function(data){ 
			if(data == 1) {
				alert('删除成功');
				obj.parents(".facility-img").remove();	
			}
		});
	}	
});


</script>	
</div>
<{include file="admin/footer.html"}>
